//
//  DownloadListCell.swift
//  GhostWorld
//
//  Created by Kam on 2018/5/21.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

class DownloadListCell: UITableViewCell {

  // MARK: - IBOutlets
  
  @IBOutlet private weak var downloadCellContentView: UIView!
  @IBOutlet private weak var coverImageView: UIImageView!
  @IBOutlet private weak var albumNameLabel: UILabel!
  @IBOutlet private weak var descriptionLabel: UILabel!
  
  // MARK: - Private vars
  
  private let selectView = UIView()
  
  // MARK: - Private methods
  
  
  
  // MARK: - Public vars
  
  
  
  // MARK: - Lifecycle
  
  override func awakeFromNib() {
    super.awakeFromNib()
    
    downloadCellContentView.layer.cornerRadius = 4
    downloadCellContentView.clipsToBounds = true
    
    // selected background view
    let backgroundView = UIView()
    backgroundView.backgroundColor = .clear
    
    selectView.backgroundColor = UIColor(fromRGB: 0x98000C)
    selectView.clipsToBounds = true
    selectView.layer.cornerRadius = 4
    backgroundView.addSubview(selectView)
    selectedBackgroundView = backgroundView
  }
  
  override func layoutSubviews() {
    super.layoutSubviews()
    
    selectView.frame = downloadCellContentView.frame
  }
  
  override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    
    // Configure the view for the selected state
  }
  
  // MARK: - IBActions
  
  
  
  // MARK: - Public methods
  
  func prepare(album: Album, totalFileSize: Float, downloadedCount: Int) {
    albumNameLabel.text = album.name
    if let url = album.cover.getURL(size: .thumb) {
      coverImageView.af_setImage(withURL: url)
    }
    descriptionLabel.text = "\(downloadedCount)个声音，共\(String(format: "%.1f", totalFileSize))M"
  }
}

extension DownloadListCell {
  static let defaultHeight: CGFloat = 90
}

